package com.zsx.shopping.product.controller;

import com.zsx.shopping.common.api.R;
import com.zsx.shopping.common.api.product.vo.SkuVO;
import com.zsx.shopping.product.service.SkuService;
import com.zsx.shopping.product.vo.app.GoodsVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product/sku")
public class SkuController {

    @Resource
    private SkuService skuService;

    @GetMapping("/goods")
    public R<GoodsVO> getGoods(@RequestParam Long skuId) {
        return R.success(skuService.getGoods(skuId));
    }

    @GetMapping("/skus")
    public R<List<SkuVO>> getSkus(@RequestParam List<Long> skuIds) {
        return R.success(skuService.getSkus(skuIds));
    }

    @PostMapping("/totalPrice")
    public R<BigDecimal> getTotalPrice(@RequestBody Map<Long, Integer> map) {
        return R.success(skuService.getTotalPrice(map));
    }

    @PutMapping("/cache/goods")
    public R<Void> cacheGoods(@RequestParam List<Long> skuIds) {
        skuService.cacheGoods(skuIds);
        return R.success();
    }
}
